#include "plugin_modbus.h"

/**
 * @brief plugin_modbus::initUi 初始化ui
 */
void plugin_modbus::initUi()
{
    static bool initFlag = true;
    if(initFlag){
        initFlag = false;
        // plugin_modbus_ui->verticalLayout->addWidget(&m_configWidget);
        QObject::connect(&modbus_interface, &modbus_serialport::signalToForward,
                         this, [this](const QString& arg) { // 改用const引用
                             emit messageFromPlugin(pluginName(), arg);
                         });
    }
}

/**
 * @brief sendMessageToPlugin 接收来自其他任务的信息
 * @param msg
 */
void plugin_modbus::sendMessageToPlugin(const QString &msg)
{
    initUi();
    processJsonCommand(msg);
}
/**
 * @brief plugin_modbus::processJsonCommand 解析json字符串并将内容赋值到m_dataBlockMap
 * @param jsonStr
 */
void plugin_modbus::processJsonCommand(const QString &jsonStr)
{
    QString err = "";
    if(false == modbus_interface.processJsonCommand(jsonStr, &err))
    {
        emit messageFromPlugin(pluginName(), err);
    }
}
